package models

import "gorm.io/gorm"

type User struct {
	gorm.Model
	Name string  `gorm:"unique_index"`
	Email string `gorm:"unique_index"`
	Pwd string
	Head string   //头像
	Role int   `gorm:"default:0` //1代表管理员，0代表普通
}

func QueryUser(name string,pwd string)(int64,error,User){
	var user User
	res:=db.Where("name=? and pwd=?",name,pwd).Take(&User{}).Scan(&user)   //查询值并且扫描
	return res.RowsAffected,res.Error,user
}

func QueryUserByName(name string)(int64,error){
	res:=db.Where("name=? ",name).Take(&User{})
	return res.RowsAffected,res.Error
}

func Register(user User)error{
   return db.Create(&user).Error
}